package com.ryskoo.customer.vendorinfo.repository;

import com.ryskoo.customer.vendorinfo.domain.VendorInfoPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hh
 */
@Repository
public class VendorInfoJPAImpl extends BasicJPAImpl<VendorInfoPO> implements IVendorInfoRepository {

	/**
	 * 根据VendorUuids 查询 VendorInfo
	 * 
	 * @param VendorUuids
	 * @return
	 */
	public List<VendorInfoPO> getByVendorUuids(List<String> vendorUuids) {
		String hql = "select o from VendorInfoPO o where o.vendorUuid in (:vendorUuids)";
		Query q = getH4Session().createQuery(hql);
		q.setParameterList("vendorUuids", vendorUuids);
		List<VendorInfoPO> retList = q.list();
		return retList;
	}

	/**
	 * 根据 VendorUuid 查询 vendorInfo
	 * 
	 * @param VendorUuid
	 * @return
	 */
	public VendorInfoPO getByVendorUuid(String vendorUuid) {
		String hql = "select o from VendorInfoPO o where o.vendorUuid = :vendorUuid";
		Query q = getH4Session().createQuery(hql);
		q.setString("vendorUuid", vendorUuid);
		List<VendorInfoPO> retList = q.list();
		if (retList != null && retList.size() > 0) {
			return retList.get(0);
		}
		return null;
	}

	/**
	 * 根据 VendorUuids 删除 VendorInfo
	 * 
	 * @param List<String>
	 *            needDeleteVendorUuids
	 * @return
	 */
	public void deletesByVendorUuids(List<String> needDeleteVendorUuids) {
		String hql = "delete from VendorInfoPO o where o.vendorUuid in (:needDeleteVendorUuids)";

		Map<String, Object> mapParams = new HashMap<String, Object>();
		mapParams.put("needDeleteVendorUuids", needDeleteVendorUuids.toArray());

		this.exeUpdate(hql, mapParams);
	}
}
